package com.wq.data.capital.repository;

import com.wq.api.domain.entity.capital.CapitalAccount;
import com.wq.api.exception.InsufficientBalanceException;
import com.wq.api.repository.capital.CapitalAccountRepository;
import com.wq.data.capital.dao.CapitalAccountMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 * Created by changming.xie on 4/2/16.
 */
@Repository
@DubboService
public class CapitalAccountRepositoryImpl  implements CapitalAccountRepository {

    @Autowired
    CapitalAccountMapper capitalAccountMapper;

    @Override
    public CapitalAccount findByUserId(long userId) {

        return capitalAccountMapper.findByUserId(userId);
    }

    @Override
    public void save(CapitalAccount capitalAccount) {
        int effectCount = capitalAccountMapper.update(capitalAccount);
        if (effectCount < 1) {
            throw new InsufficientBalanceException();
        }
    }
}
